#include <avz.h>
#include "helium/helium_helper_se.h"
#include "SimpleAvZ/lib.h"
using namespace AvZ;

void Script()
{
    SeedSlot(10);                                    // 10 卡槽
    OpenMultipleEffective('Q', MAIN_UI_OR_FIGHT_UI); // 反复重开
    SetAdvancedPauseKey('Z');                        // 高级暂停
    SetSkipTickKey('S', 9);                          // 跳帧
    SetSkipTickKey('D', 19);
    SetErrorMode(NONE);
    WriteMemory<unsigned short>(0x00eb, 0x0054eba8);

    SetZombies_AllType(FE);
    SelectCards({
        DOOM,
        M_DOOM,
        CHERRY,
        JALA,
        LILY,
        PUMPKIN,
        ICE,
        PUFF,
        SUN,
        SCAREDY,
    });

    for (auto wave : waves(1, 2, 3, 7, 8, 11, 12, 16, 17, 18))
    {
        PP(341);
    }

    for (auto wave : waves(4, 13))
    {
        P(341, 2, 9);
        A(341, 5, 9);
    }

    for (auto wave : waves(5, 14))
    {
        if (wave == 5)
        {
            C(341 - 100 - 320, LILY, 3, 9);
            C(341, M_DOOM, 3, 9);
            C(after(5001), M_DOOM, 4, 8);
            C(341 + 5001 - 100 - 320 - 2, LILY, 4, 8);
            RM(341 + 5001 - 100 - 320 - 1, 1, 5);
            C(341 + 5001 - 100 - 1, PUFF, 1, 5);
        }
        else
        {
            C(341 - 100 - 320, LILY, 4, 9);
            C(341, M_DOOM, 4, 9);
        }
    }

    for (auto wave : waves(6))
    {
        N(341, 2, 9);
        J(341, 6, 9);
    }

    for (auto wave : waves(10))
    {
        PP(341);
        N(401, 3, 8);
    }

    for (auto wave : waves(15))
    {
        // N"469
        RM(exact(469 - 100 - 2), 1, 5);
        C(exact(469 - 100), PUFF, 1, 5);
    }

    for (auto wave : waves(9)) // 只有一路有巨人，没有冰瓜怎么办
    {
        PP(341);
        I(225, 1, 6);
        P(811, 2, 9);
        PP(2614, 8);
        P(3816, 2, 7.5);
        EnsureAbsent({GIGA, 2});
    }

    for (auto wave : waves(19))
    {
        P(341, 2, 9);
        N(359, 5, 8);
        I(359, 1, 6);
        PP(2013);
        P(2614, 2, 9);
        P(now, 2, 9);
        EnsureAbsent({GIGA, 2});
    }

    for (auto wave : waves(20))
    {
        B(251, 4, 7.5875);
        PP(341);
        PP(675);
        P(839 + 5, 2, 9);
        P(839 + 5, 2, 9);
        EnsureExist({GIGA, 5, 6});
    }
}

#include "showme/sm.h"
SMShowMe show_me;
void Draw()
{
    auto &&painter = show_me.getPainter();
    short int anim_index;
    for (auto &&plant : AvZ::alive_plant_filter)
    {
        if (plant.type() == POT)
        {
            anim_index = plant.animationCode();
            int x = plant.abscissa();
            int y = plant.ordinate();
            painter.drawText("动画编号：" + std::to_string(anim_index), x - 20, y + 80);
        }
    }
    for (auto &&plant : AvZ::alive_plant_filter)
    {
        if (plant.type() != POT && plant.animationCode() == anim_index)
        {
            int x = plant.abscissa();
            int y = plant.ordinate();
            painter.drawText("动画编号：" + std::to_string(anim_index), x - 20, y + 50);
        }
    }
}